package com.eleMall.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eleMall.entity.Goods;
import com.eleMall.entity.Result;
import com.eleMall.mapper.GoodsMapper;
import com.eleMall.service.GoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ximen
 * @since 2024-03-10
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Override
    public List<Goods> getHotGoods() {
        LambdaQueryWrapper<Goods> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.orderByDesc(Goods::getClick)
                .last("LIMIT 4");
        return this.list(lambdaQueryWrapper);
    }

    @Override
    public Page<Goods> getShowListPlus(int current, int size, int matching) {
        Page<Goods> pageInfo = new Page<>(current, size);

        if(matching == 4){
            this.page(pageInfo, Wrappers.<Goods>lambdaQuery()
                    .orderByDesc(Goods::getCreateTime));
        }else {
            this.page(pageInfo, Wrappers.<Goods>lambdaQuery()
                    .eq(Goods::getSortId,matching)
                    .orderByDesc(Goods::getCreateTime));
        }

        return pageInfo;
    }
}
